package com.oa.controller;

import com.oa.pojo.Dept;
import com.oa.pojo.Duty;
import com.oa.pojo.Result;
import com.oa.service.DutyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "职务：在线接口")
@RequestMapping("/duty")
public class dutyController {

    @Autowired
    private DutyService dutyService;

    @CrossOrigin
    @ApiOperation(value="根据职务条件查询(id,deptId,dutyName)",httpMethod = "GET",notes = "返回包含用户类的result类型json格式")
    @GetMapping("selectAll")
    public Result selectAll(Integer id,Integer deptId,String dutyName){
        System.out.println("执行查询职务的接口");
        Duty duty = new Duty();
        duty.setId(id);
        duty.setDeptId(deptId);
        duty.setDutyName(dutyName);
        List<Duty> dutyList= dutyService.selectDuty(duty);
        return Result.success(dutyList);
    }

    @CrossOrigin
    @ApiOperation(value="根据职务删除(id)",httpMethod = "GET",notes = "返回包含用户类的result类型json格式")
    @GetMapping("/deleteDuty")
    public Result deleteDuty(Integer id){
        System.out.println("执行删除职务接口");

        int flag= dutyService.deleteDuty(id);
        if (flag==1){
            return Result.success();
        }else {
            return Result.error("没有此id的职务");
        }
    }

    @CrossOrigin
    @ApiOperation(value="职务信息更改",httpMethod = "POST",notes = "返回的result类型json格式")
    @PostMapping("/updateDuty")
    public Result updateDuty(@RequestBody Duty duty){
        System.out.println("执行职务信息修改接口");

        int flag= dutyService.updateDuty(duty);
        if (flag==1) {
            return Result.success();
        }else {
            return Result.error("添加新部门失败，有重复属性");
        }
    }

    @CrossOrigin
    @ApiOperation(value="添加职务",httpMethod = "POST",notes = "返回的result类型json格式")
    @PostMapping("/insertDuty")
    public Result insertDuty(@RequestBody Duty duty){
        System.out.println("执行添加职务接口");

        int flag= dutyService.insertDuty(duty);

        if (flag==1) {
            return Result.success();
        }else {
            return Result.error("添加新部门失败，有重复属性");
        }
    }
}
